package exer;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;

/**
 * @author tongchen
 * @create 2023-04-05 17:31
 */
@WebServlet("/upload")
@MultipartConfig
public class Upload extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取上传上来的文件：
        Part uploadFile = req.getPart("uploadFile");
        //测试方法
        System.out.println(uploadFile.getSubmittedFileName());
        System.out.println(uploadFile.getContentType());
        System.out.println(uploadFile.getSize());
        //存储文件
        uploadFile.write("D:/360安全浏览器下载/"+uploadFile.getSubmittedFileName());
        resp.setContentType("text/html; charset=utf-8");
        resp.getWriter().write("文件下载成功");

    }
}
